package cn.shop.gameapi.model;

import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

public interface SqlContent {

    String SELECT_SECRET_IP = "select id, uid, ip, secret from gateway_secret " +
            "where ip = ? and deleted = false";

    String SELECT_SECRET_IP_UID = "select id, uid, ip, secret from gateway_secret " +
            "where ip =? and uid = ? and deleted = false";
    String INSERT_SECRET = "insert into gateway_secret(id, uid, ip, secret) " +
            "values(?, ?, ?, ?)";
    String UPDATE_SECRET = "update gateway_secret set uid=?, secret=? where ip=?";

    String SELECT_MERCHANT = "select id, account, password from merchant_user " +
            "where account = ? and deleted = false and state = 2";

    String SELECT_MERCHANT_BY_ID = "select id, account, password from merchant_user " +
            "where id = ? and deleted = false and state = 2";

    String SELECT_TEMPLATE_ID = "select id, name, rate, charge,game_currency from merchant_game_template " +
            "where id = ? and deleted = false";

    String SELECT_TEMPLATE_UID = "select id, name, rate, charge, multiple, game_currency, browser_command from merchant_game_template " +
            "where uid = ? and deleted = false";
    String SELECT_TEMPLATE_UID_ID = "select id, name, rate, charge, multiple, game_currency, browser_command from merchant_game_template " +
            "where uid = ? and id = ? and deleted = false";

    String SELECT_BIND = "select id, user_id, merchant_id, game_id, partition_id, account, nickname " +
            "from game_bind where account = ? and partition_id = ? and nickname = ? and deleted = false";

    String INSERT_ORDER = "insert into `order`(id, uid, template_id, partition_id, seller_id, seller_account, seller_name, goods, goods_num, back_num, amount, status, template_charge, create_time, deleted, update_time, goods_type) " +
            "values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
    String SELECT_ORDER = "select id, uid, partition_id, buyer_account, buyer_name, seller_account, seller_name, goods, goods_num, back_num from `order` where id = ? and deleted = false";

    String SELECT_PARTITION = "select\n" +
            "    gp.id, gp.uid, gp.template_id, gp.name, gp.server_folder, gp.ip, gp.port, gp.create_script,\n" +
            "    ma.alias\n" +
            "from merchant_game_partition gp\n" +
            "left join merchant_game_info gi on gi.id = gp.game_id and gi.deleted = false\n" +
            "left join merchant_alias ma on ma.id = gi.alias_id and ma.deleted = false\n" +
            "where gp.id = ? and gp.deleted = false";

    String SELECT_PARTITION_T_P = "select\n" +
            "    gp.id, gp.template_id, gp.name, gp.server_folder, gp.ip, gp.port, gp.create_script,\n" +
            "    ma.alias\n" +
            "from merchant_game_partition gp\n" +
            "left join merchant_game_info gi on gi.id = gp.game_id and gi.deleted = false\n" +
            "left join merchant_alias ma on ma.id = gi.alias_id and ma.deleted = false\n" +
            "where gp.template_id = ? and gp.ip = ? and gp.uid = ? and gp.deleted = false";

    String SELECT_NPC = "select id, partition_id, name, map_code, position_x, position_y, style_code from game_npc where partition_id = ?";

    String SELECT_RATE = "select id, charge_single, charge_rate, single_type, rate_type, single_additional, rate_additional from merchant_rate where id = ?";

    String INSERT_RATE = "insert into order_rate(id, create_time, charge_single, charge_rate, single_type, rate_type, single_additional, rate_additional) values (?,?,?,?,?,?,?,?)";

    static <T> T selectOne(JdbcTemplate template, String sql, BeanPropertyRowMapper<T> rowMapper, Object... params) {
        T t = null;
        try {
            t = template.queryForObject(sql, rowMapper, params);
        } catch (Exception ignored) {}
        return t;
    }

}
